package com.cqq.print.business.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cqq.common.core.bean.PageInfoBean;
import com.cqq.print.business.dao.PProduceDao;
import com.cqq.print.business.dao.PProduceDetailDao;
import com.cqq.print.business.dao.domain.PProduce;
import com.cqq.print.business.service.bean.PProduceBean;


/**
 * @author generated
 * @date 2015-07-01
 */


@Service(value="pProduceService")
public class PProduceServiceImpl implements com.cqq.print.business.service.PProduceService{

             @Autowired
             private PProduceDao pProduceDao;
             @Autowired
             private PProduceDetailDao pProduceDetailDao;

			
			public PageInfoBean<PProduceBean> queryPageProduces(
					Map<String, Object> map) {
				List<PProduceBean> listPPBean = null;
				List<PProduce> listPP = pProduceDao.queryProduces(map);
				int count = pProduceDao.queryProducesCount(map);
				if(listPP!=null && listPP.size()>0){
					listPPBean = new ArrayList<PProduceBean>();
					for (PProduce pp : listPP) {
						PProduceBean ptBean = new PProduceBean();
						BeanUtils.copyProperties(pp, ptBean);
						listPPBean.add(ptBean);
					}
				}
				
				return new PageInfoBean<PProduceBean>(listPPBean, count);
			}

			
			public int insertSelective(PProduceBean record) {
				if(record==null)
					return 0;
				PProduce pp = new PProduce();
				BeanUtils.copyProperties(record, pp);
				return pProduceDao.insertSelective(pp);
			}

			
			public int updateByPrimaryKey(PProduceBean record) {
				if(record==null||record.getId()==null)
					return 0;
				PProduce pp = new PProduce();
				BeanUtils.copyProperties(record, pp);
				return pProduceDao.updateByPrimaryKeySelective(pp);
			}

			
			public List<PProduceBean> queryProduces(Map<String, Object> map) {
				List<PProduceBean> listPPBean = null;
				List<PProduce> listPP = pProduceDao.queryProduces(map);
				if(listPP!=null && listPP.size()>0){
					listPPBean = new ArrayList<PProduceBean>();
					for (PProduce pp : listPP) {
						PProduceBean ptBean = new PProduceBean();
						BeanUtils.copyProperties(pp, ptBean);
						listPPBean.add(ptBean);
					}
				}
				
				return listPPBean;
			}

			
			public PProduceBean queryProduceById(Integer id) {
				PProduce pp = pProduceDao.queryProduceById(id);
				PProduceBean ppBean = new PProduceBean();
				BeanUtils.copyProperties(pp, ppBean);
				return ppBean;
			}

			
			public PProduceBean queryProduceByOrderNum(String orderNum) {
				PProduce pp = pProduceDao.queryProduceByOrderNum(orderNum);
				PProduceBean ppBean = new PProduceBean();
				BeanUtils.copyProperties(pp, ppBean);
				return ppBean;
			}

			
			public int updateCheckStatus(PProduceBean ppBean) {
				if(ppBean==null||ppBean.getId()==null||ppBean.getCheckStatus()==null)
					return 0;
				PProduce pp = new PProduce();
				BeanUtils.copyProperties(ppBean, pp);
				return pProduceDao.updateByPrimaryKeySelective(pp);
			}

			
			public void deleteProduce(Integer id) {
				//1、删除生产订单明细
				pProduceDetailDao.deleteByProduceId(id);
				//2、删除生产订单
				pProduceDao.deleteByPrimaryKey(id);
				
			}

}